package com.sg.business.model.dataset.project;

import java.util.ArrayList;
import java.util.List;

import org.bson.types.ObjectId;

import com.mobnut.db.model.PrimaryObject;
import com.mongodb.BasicDBObject;
import com.sg.business.model.Folder;
import com.sg.business.model.IModelConstants;
import com.sg.business.model.Organization;
import com.sg.business.model.Project;
import com.sg.widgets.commons.dataset.OptionDataSetFactory;

public class ProjectDocumentContainerOfOrg extends OptionDataSetFactory {

	public ProjectDocumentContainerOfOrg() {
		super(IModelConstants.DB, IModelConstants.C_FOLDER);
	}

	@Override
	public void setEditorData(PrimaryObject data) {
		Project project = (Project) data;
		Organization functionOrg = project.getFunctionOrganization();
		if (functionOrg != null) {
			List<ObjectId> containerIds = new ArrayList<ObjectId>();
			Organization containerOrg = functionOrg.getContainerOrganization();
			containerIds.addAll(containerOrg.getContainerIds());
			setQueryCondition(new BasicDBObject().append(
					Folder.F__ID,
					new BasicDBObject().append("$in",
							containerIds.toArray(new ObjectId[0]))));
		}
		super.setEditorData(data);
	}

}
